/*  
 * Video Game Network Library
 * http://gamenetlib.codeplex.com/
 * 
 * Copyright (c) 2011 Joe Hegarty
 *  
 * This source code is subject to the terms of the Microsoft Public License (Ms-PL). 
 *  
 * Redistribution and use in source and binary forms, with or without modification, 
 * is permitted provided that redistributions of the source code retain the above 
 * copyright notices and this file header. 
 * 
 * For details, see <http://www.opensource.org/licenses/ms-pl.html>. 
 *  
 * All other rights reserved. 
 *
 */  

#include "StandardIncludes.hpp"
#include "NetLib.hpp"

NNetLib::CNetLib* NNetLib::g_netLib = NULL;

bool NNetLib::CNetLib::Initialise()
{
	::WSADATA wsaData = { 0 };
	int startupResult = ::WSAStartup(MAKEWORD(2,2), &wsaData);
	return startupResult == ERROR_SUCCESS;
}

bool NNetLib::CNetLib::Shutdown()
{
	int shutdownResult = ::WSACleanup();
	return shutdownResult == ERROR_SUCCESS;
}

bool NNetLib::StartNetLib()
{
	if(!g_netLib)
	{
		g_netLib = new CNetLib();
		return g_netLib->Initialise();
	}

	return false;
}

bool NNetLib::ShutdownNetLib()
{
	bool shutdownResult = false;
	if(g_netLib)
	{
		shutdownResult = g_netLib->Shutdown();
		delete g_netLib;
		g_netLib = NULL;
	}

	return shutdownResult;
}

